﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tango.Core.Data;
using Tango.IServices;

namespace Tango.Service
{
    public class BaseService<T> : IBaseService<T> where T : class,new()
    {
        protected readonly IEFRepository<T> _repository;

        #region 构造

        public BaseService(IEFRepository<T> repository)
        {
            this._repository = repository;
        }
        #endregion

        #region 方法
        public IQueryable<T> GetAll()
        {
            return _repository.GetAll();
        }

        public T Get(long ID)
        {
            return _repository.Get(ID);
        }

        public T Get(string ID)
        {
            return _repository.Get(ID);
        }

        public void Update(T entity)
        {
            _repository.Update(entity);
        }

        public void Add(T entity)
        {
            _repository.Add(entity);
        }

        public void Delete(T entity)
        {
            _repository.Delete(entity);
        }

        public void Delete(System.Linq.Expressions.Expression<Func<T, bool>> where)
        {
            _repository.Delete(where);
        }

        public T Get(System.Linq.Expressions.Expression<Func<T, bool>> where)
        {
            return _repository.Get(where);
        }

        public IQueryable<T> GetMany(System.Linq.Expressions.Expression<Func<T, bool>> where)
        {
            return _repository.GetMany(where);
        }
        #endregion
    }
}
